package com.example.fw;

import org.openqa.selenium.By;

public class NavigationHelper extends WebDriverHelperBase{

	public NavigationHelper(AppManager manager) {
		super(manager);
	}

	public void groupsPage() {
		if (! onGroupsPage()){
			click(By.linkText("groups"));
		}
	}

	private boolean onGroupsPage() {
		return (driver.getCurrentUrl().contains("/group.php") && driver.findElements(By.name("new")).size() > 0);
	}

	public void returnToHomePage() {
		click(By.linkText("home page"));
	}

	public void mainPage() {
		if (! onMainPage())
			click(By.linkText("home"));
	}
	
	public void mainPageByGet() {
		if (! onMainPage())
			driver.get(manager.baseUrl + "/addressbookv4.1.4/");
	}
	
	private boolean onMainPage() {
		return driver.findElements(By.id("maintable")).size() > 0;
	}

	public void newContactPage() {
		if (! onNewContactPage())
			click(By.linkText("add new"));
	}

	private boolean onNewContactPage() {
		return (driver.getCurrentUrl().contains("/edit.php") && driver.findElements(By.name("new_group")).size() > 0);
	}

	public void allPrintPhonesPage() {
		if (! onAllPrintPhonesPage())
			click(By.linkText("print phones"));
	}

	private boolean onAllPrintPhonesPage() {
		return driver.getCurrentUrl().contains("/view.php?all&print&phones");
	}
	
}
